package com.jaydenxiao.common.actionUtil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Administrator on 2016/12/21.
 */

public class RegexUtils {



    public static String interNumber="[0-9]+.[0-9]+";

    public static String emailRegex="^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$";

    public static String cardRegex="(^\\d{18}$)|(^\\d{15}$)";


    public static String regNumber="[^0-9]";




    public static String getNumberByRegex(String content){
        String a=content;
        Pattern p = Pattern.compile(regNumber);
        Matcher m = p.matcher(a);
        return m.replaceAll("").trim();
    }







    public static boolean isLegalString(String pattern, String content){
        boolean isLegal=false;

        boolean matches = Pattern.matches(pattern, content);
        if(matches){
            return true;
        }


        Pattern compile = Pattern.compile(pattern);
        Matcher matcher = compile.matcher(content);


        boolean b = matcher.find();
        if (b) {
            isLegal=true;

        }
        return isLegal;
    }

    public static boolean isLegalStringList(String content, String... patternList){

        boolean isLegal=false;


        for (String pattern : patternList) {
            Pattern compile = Pattern.compile(pattern);
            Matcher matcher = compile.matcher(content);
            if (matcher.find()) {
                isLegal=true;
                return  isLegal;
            }
        }
        return isLegal;
    }



    public static double  getDoubleByRegex(String pattern, String content) {

        double price=-1;

        Pattern compile = Pattern.compile(pattern);

        Matcher matcher = compile.matcher(content);
        if (matcher.find()) {

            price= Double.valueOf(matcher.group(0));


        }



        return price;
    }
}
